package com.liuyi.netty.im.test.lychat.config;


import com.liuyi.rapid.develop.tool.SpringContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

@Component
@EnableAsync
public class AsyncExecute {

    private static AsyncExecute asyncExecute;

    public static AsyncExecute me() {
        if (asyncExecute == null) {
            asyncExecute = SpringContext.getBean(AsyncExecute.class);
        }
        return asyncExecute;
    }

    @Async
    public void async(ExecuteFunction execute) {
        execute.execute();
    }

    @FunctionalInterface
    public interface ExecuteFunction {

        void execute();

    }
}
